﻿@{
    Layout = null;
    var media = new DirectoryInfo(Server.MapPath("~/Media"));
}
<html>
    <head>
        <title>Media Browser</title>
        <link href="~/Content/admin.css" type="text/css" rel="stylesheet" />
        <script src="/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
        <script src="/Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
        <script type="text/javascript">
            var funcNum = @(Request["CKEditorFuncNum"] + ";")
            $(function() {
                $('li').click(function() {
                    $('#fileExplorer').load('/Admin/Ajax/ImageViewer?directory=' + encodeURIComponent($(this).text()));
                });
                $('#fileExplorer').on('click', 'img', function () {
                    var fileUrl = '/Media/' + $(this).attr('title');
                    window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
                    window.close();
                }).hover(function() {
                    $(this).css('cursor', 'pointer');
                });
                $('#folderExplorer').hover(function() {
                    $(this).css('cursor', 'pointer');
                });
            });
        </script>
    </head>
    <body>
        <div id="folderExplorer">
            <ul>
            @foreach (var directory in media.EnumerateDirectories().Where(d => d.GetFilesByExtensions(".png", ".gif", ".jpg").Any())) {
                <li>@directory.Name</li>
            }
            </ul>
        </div>
       <div id="fileExplorer"></div>
    </body>
</html>
